<extend name="Public/base"/>

<block name="body">
	<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
	<div class="main-title">
		<h2>{:isset($info['id'])?'编辑':'新增'}品牌推广</h2>
	</div>
	<div class="tab-wrap">
		<ul class="tab-nav nav">
			<li data-tab="tab1" class="current"><a href="javascript:void(0);">基 础</a></li>
			<li data-tab="tab2"><a href="javascript:void(0);">高 级</a></li>
		</ul>
		<div class="tab-content">
			<form action="{:U()}" method="post" class="form-horizontal">
				<!-- 基础 -->
				<div id="tab1" class="tab-pane in tab1">
				<div class="form-item">
						<label class="item-label">所属分类<span class="check-tips">（品牌所属分类<b id='pid'></b>）</span></label>
						<div class="controls">
							<select id="firstlever"> 
  <option value="-1">选择一级分类</option>
  <volist name="list" id="vo" > 
  <option  value="{$vo.id}" >{$vo.title}</option>  
   </volist></select> 
   <select id="secondlever"> <option value="-1">选择二级分类</option> </select>
 <select id="thirdlever"> <option value="-1">选择三级分类</option> </select>
	
	<script>
	$('#firstlever').change(function(){
					if(this.value==-1){
						//$('#ltwo').hide();
						//$('#lthree').hide();
						return;
					}
						$('#ypid').val(this.value);//写入数据
                      $('b').html(this.value);//写入数据
					$.post('{:U("change")}',{pid:this.value},
					function(data,textStatus){
						if(data){
						    $('#secondlever').empty();//清空原有的数据
							//$("<option value='-1'>选择三级分类</option>").appendTo("#thirdlever");
							
						
							//$("<option value='-1'>选择二级分类</option>").appendTo("#secondlever");
							
								$.each(data, function(i,n){
								$("<option value='"+n.id+"'>"+n.title+"</option>").appendTo("#secondlever");
								//$("#ltwo").append('<option value="'+n.region_id+'">'+n.region_name+'</option>');
							});
							$('#ltwo').show();
						}else{
							alert('没有子级了!');
						}
					},'json');
				});
$('#secondlever').change(function(){
					if(this.value==-1){
						//$('#ltwo').hide();
						//$('#lthree').hide();
						return;
					}
					$('#ypid').val(this.value);//写入数据
					$('b').html(this.value);//写入数据
					$.post('{:U("change")}',{pid:this.value},
					function(data,textStatus){
						if(data){
						
					  $('#thirdlever').empty();//清空原有的数据
					
							$.each(data, function(i,n){
								$("<option value='"+n.id+"'>"+n.title+"</option>").appendTo("#thirdlever");
								//$("#ltwo").append('<option value="'+n.region_id+'">'+n.region_name+'</option>');
							});
							$('#ltwo').show();
						}else{
							alert('没有子级了!');
						}
					},'json');
				});

$('#thirdlever').change(function(){
					if(this.value==-1){
						//$('#ltwo').hide();
						//$('#lthree').hide();
						return;
					}
					//alert($('#lone'.value);
						$('#ypid').val(this.value);//写入数据
                       $('b').html(this.value);//写入数据
				});

				</script>
				</div>
					</div>
					<div class="form-item">
						<label class="item-label">
							品牌名称<span class="check-tips">（多个商品用逗号隔开，如3,4,5）</span>
						</label>
						<div class="controls">
							<input type="text" name="title" class="text input-large" value="{$info.title|default=''}">
						</div>
					</div>
	<div class="form-item">
						<label class="item-label">
							品牌标识<span class="check-tips">（英文字母，不可重复）</span>
						</label>
						<div class="controls">
							<input type="text" name="name" class="text input-large" value="{$info.name|default=''}">
						</div>
					</div>
					<div class="controls">
						<label class="item-label">图片</label>
						<input type="file" id="upload_picture">
						<input type="hidden" name="icon" id="icon" value="{$info['icon']|default=''}"/>
						<div class="upload-img-box">
						<notempty name="info['icon']">
							<div class="upload-pre-item"><img src="{$info.icon|get_cover='path'}"/></div>
						</notempty>
						</div>
					</div>
					<div class="form-item">
						<label class="item-label">状态<span class="check-tips">（1-可用，2-禁用）</span></label>
						<div class="controls">
							<label class="textarea input-large">
								<input type="text" name="status" class="text input-large" value="{$info.status|default='1'}">
							</label>
						</div>
					</div>
					<script type="text/javascript">
					//上传图片
				    /* 初始化上传插件 */
					$("#upload_picture").uploadify({
				        "height"          : 30,
				        "swf"             : "__STATIC__/uploadify/uploadify.swf",
				        "fileObjName"     : "download",
				        "buttonText"      : "上传图片",
				        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
				        "width"           : 120,
				        'removeTimeout'	  : 1,
				        'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
				        "onUploadSuccess" : uploadPicture,
				        'onFallback' : function() {
				            alert('未检测到兼容版本的Flash.');
				        }
				    });
					function uploadPicture(file, data){
				    	var data = $.parseJSON(data);
				    	var src = '';
				        if(data.status){
				        	$("#icon").val(data.id);
				        	src = data.url || '__ROOT__' + data.path;
				        	$("#icon").parent().find('.upload-img-box').html(
				        		'<div class="upload-pre-item"><img src="' + src + '"/></div>'
				        	);
				        } else {
				        	updateAlert(data.info);
				        	setTimeout(function(){
				                $('#top-alert').find('button').click();
				                $(that).removeClass('disabled').prop('disabled',false);
				            },1500);
				        }
				    }
					</script>
				</div>

				<!-- 高级 -->
				<div id="tab2" class="tab-pane tab2">
					<div class="form-item">
						<label class="item-label">可见性<span class="check-tips">（是否对用户可见，针对前台）</span></label>
						<div class="controls">
							<select name="display">
								<option value="1">所有人可见</option>
								<option value="0">不可见</option>
								<option value="2">管理员可见</option>
							</select>
						</div>
					</div>
					

				</div>

				<!-- 高级 -->
				<div id="tab2" class="tab-pane tab2">
					<div class="form-item">
						<label class="item-label">网页标题</label>
						<div class="controls">
							<input type="text" name="meta_title" class="text input-large" value="{$info.meta_title|default=''}">
						</div>
					</div><div class="form-item">
						<label class="item-label">描述</label>
						<div class="controls">
							<label class="textarea input-large">
								<textarea name="description">{$info.description|default=''}</textarea>
							</label>
						</div>
					</div>
					
					
					
					
				</div>

				<div class="form-item">
					<input type="hidden" name="id" value="{$info.id|default=''}">
					<input type="hidden" name="ypid" id="ypid" value="{$info.ypid|default=''}">
					<button type="submit" id="submit" class="btn submit-btn ajax-post" target-form="form-horizontal">确 定</button>
					<button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
				</div>
		</form>
		</div>
	</div>
</block>

<block name="script">
	<script type="text/javascript">
		<present name="info.id">
		Think.setValue("allow_publish", {$info.allow_publish|default=1});
		Think.setValue("check", {$info.check|default=0});
		Think.setValue("model[]", {$info.model|json_encode} || [1]);
		Think.setValue("model_sub[]", {$info.model_sub|json_encode} || [1]);
		Think.setValue("type[]", {$info.type|json_encode} || [2]);
		Think.setValue("display", {$info.display|default=1});
		Think.setValue("reply", {$info.reply|default=0});
		Think.setValue("reply_model[]", {$info.reply_model|json_encode} || [1]);
		</present>
		$(function(){
			showTab();
			$("input[name=reply]").change(function(){
				var $reply = $(".form-item.reply");
				parseInt(this.value) ? $reply.show() : $reply.hide();
			}).filter(":checked").change();
		});
		//导航高亮
		highlight_subnav('{:U('Brand/index')}');
	</script>
</block>
